package com.neuedu.api.lang;

import java.util.Objects;

/**
 * @author 金山
 * 项目：javase
 * site: https://blog.fulfill.com.cn
 * 描述
 * @data 2024/10/2116:28
 */
public class Student  {


    private int stuNo;
    private int age;

    public Student(int stuNo, int age) {
        this.stuNo = stuNo;
        this.age =  age;
    }


    @Override
    public boolean equals(Object o) {
        if (this == o){
            return true;
        };
        if (o == null || getClass() != o.getClass()){
            return false;
        };
        Student student = (Student) o;
        return stuNo == student.stuNo && age == student.age;
    }

    @Override
    public int hashCode() {
        return Objects.hash(stuNo, age);
    }

    /**
     * 逻辑相等
     * @param o
     * @return
     */




    public static void main(String[] args) {

        Student student1 = new Student(2204201,18);
        Student student2 = new Student(2204201,18);


        System.out.println("(student1== student2) = " + (student1 == student2));  //false

        //逻辑相等的

        System.out.println("student1.equals(student2) = " + student1.equals(student2));


        String str1 = new String("abc");
        String str2 = new String("abc");

        System.out.println("str1 == str2 : "+(str1 == str2));


        //String这个类重写了  equals的方法
        System.out.println("str1.equals(str2): " + (str1.equals(str2)));


    }
}
